// 用户信息
module.exports = app => {
    const { STRING, INTEGER } = app.Sequelize;
    const User = app.model.define('user', {
        username: {
            type: STRING,
            unique: true,
            allowNull: false,
            comment: '用户名',
        },
        name:{
            type:STRING,
            unique: true,
            allowNull: false,
            primaryKey: true, // 是否为主键
            comment:'班主任/用户名'
        },
        password: {
            type: STRING,
            allowNull: false,
            comment: '密码'
        },
        sex: {
            type: STRING,
            comment: "性别"
        },
        email: {
            type: STRING,
            unique: true,
            comment: "邮箱"
        },
        phone: {
            type: STRING,
            allowNull: false,
            comment: '电话号'
        },
        state: {
            type: STRING,
            allowNull: false,
            comment: "用户状态"
            // 0 or 1
        },
        project_name: {
            type: STRING,
            comment: "所属项目"
        },
        rolename_name: {
            type: STRING,
            comment: "角色管理"
        },
        // class_name: {
        //     type: STRING,
        //     comment: "班级列表"
        // },
        // cruxname_name: {
        //     type: STRING,
        //     comment: "姓名",
        // },
    })
    User.associate = function () {
        app.model.User.belongsTo(app.model.Project, {
            foreignkey: 'project_name',
            targetkey: 'name',
            as: 'project'
        })
        app.model.User.belongsTo(app.model.Rolename, {
            foreignkey: 'rolename_name',
            targetkey: 'name',
            as: 'rolename'
        })
        // app.model.User.belongsTo(app.model.Class, {
        //     foreignkey: 'class_name',
        //     targetkey: 'name',
        //     as: 'class'
        // })
        // app.model.User.belongsTo(app.model.Cruxname, {
        //     foreignkey: 'cruxname_name',
        //     targetkey: 'name',
        //     as: 'cruxname'
        // })
    }
    return User
}